package com.zilla.android.zillacore.libzilla.util;

import android.text.Html;
import android.view.View;
import android.widget.EditText;
import com.mobsandgeeks.saripaar.Rule;
import com.mobsandgeeks.saripaar.Validator;

/**
 * Created by chenze on 13-12-26.
 */
public class ValidatorControllor {

    public static Validator initValidator(Validator.ValidationListener listener) {
        Validator validator = new Validator(listener);
        validator.setValidationListener(listener);
        return validator;
    }

    public static void onValidationFailed(View failedView, Rule<?> failedRule) {
        String message = failedRule.getFailureMessage();
        if (failedView instanceof EditText) {
            failedView.requestFocus();
            ((EditText) failedView).setError(Html.fromHtml("<font color=#808183>" + message + "</font>"));
        }
    }
}
